package character.writer;

import java.io.UnsupportedEncodingException;
import java.util.Arrays;

//字符转字节,中文转字节后都是负数
public class StringDemo1 {
    public static void main(String[] args) throws UnsupportedEncodingException {
        String s="你好，你好";
        byte[] bytes = s.getBytes();
        System.out.println(bytes);
        System.out.println("bytes数组："+Arrays.toString(bytes));
        System.out.println((Arrays.toString(bytes)).length());
        byte[] gbks=s.getBytes("gbk");
        System.out.println(gbks);
        System.out.println(Arrays.toString(gbks));
        System.out.println("_____________");
        byte[] utf8Bytes={-28, -67, -96, -27, -91, -67, -17, -68, -116, -28, -67, -96, -27, -91, -67};
        byte[] gbkBytes={-60, -29, -70, -61, -93, -84, -60, -29, -70, -61};
        String s1=new String(utf8Bytes);
        System.out.println(s1);
        String s2=new String(gbkBytes,"GBK");
        System.out.println(s2);
    }

}
